Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional args and kwargs arguments to on_success and on_failure #55

Merged

Conversation

ITz-Viks
Copy link
Contributor

@ITz-Viks ITz-Viks commented Aug 30, 2023

I also added typehinting for both functions and the new kwargs and args arguments in RustSocket.connect()

My test code

import asyncio
from rustplus_.rustplus import RustSocket

async def on_success(*args, **kwargs):
    print(f"Success: Ip is {kwargs['ip']} and port is {kwargs['port']}")


def on_failure(*args, **kwargs):
    print(f"Error: Ip is {kwargs['ip']} and port is {kwargs['port']}")

async def main():
    socket = RustSocket("ip", "port", steamid, player_token)
    kwargs = {"ip": "ip", "port": port}
    await socket.connect(on_failure=on_failure, on_success=on_success, on_success_kwargs=kwargs, on_failure_kwargs=kwargs)
    print(f"It is {(await socket.get_time()).time}")

    await socket.disconnect()

asyncio.run(main())

@ITz-Viks ITz-Viks changed the title Added optional kwargs and args for both on_success and on_failure. Removed __pycache__ leftovers. Aug 30, 2023
@ITz-Viks ITz-Viks changed the title Removed __pycache__ leftovers. Added optional args and kwargs arguments to on_success and on_failure Aug 30, 2023
@ITz-Viks
Copy link
Contributor Author

Updated per request

Copy link
Owner

@olijeffers0n olijeffers0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure whether to bundle the on_failure into the tuple as well... What do you think? as long as it is type hinted properly it should be fine

rustplus/api/base_rust_api.py Outdated Show resolved Hide resolved
rustplus/api/base_rust_api.py Outdated Show resolved Hide resolved
rustplus/api/remote/rustws.py Outdated Show resolved Hide resolved
@ITz-Viks
Copy link
Contributor Author

I'm unsure whether to bundle the on_failure into the tuple as well... What do you think? as long as it is type hinted properly it should be fine

I don't think that should change. Keeping args and functions themselves separate makes it simple to understand and whoever needs args will find it anyway. I'm not home right now so ill make the changes later/tomorrow.

@ITz-Viks ITz-Viks requested a review from olijeffers0n August 30, 2023 19:17
@olijeffers0n olijeffers0n merged commit be46782 into olijeffers0n:master Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants